﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DbfDotNet
{

    [Record(FieldMapping = FieldMapping.ExplicitColumnsOnly)]
    public class Record : IDisposable
    {

        private Core.RecordHolder mmHolder;


        public Record()
        {
#if DUMP_FINALIZE
            System.Diagnostics.Trace.WriteLine("New " + this.GetType().Name);
#endif
        }

        public object GetField(int i)
        {
            return mmHolder.GetRecordField(this, i);
        }


        internal Core.RecordHolder mHolder
        {
            get { return mmHolder; }
        }

        internal void SetHolderForNewRecord(Core.RecordHolder value)
        {
            System.Diagnostics.Debug.Assert(mmHolder==null,"mHolder can only be set once");
#if DUMP_FINALIZE
            System.Diagnostics.Trace.WriteLine(this.GetType().Name + " #" + value.mRecordNo);
#endif
            mmHolder = value;
        }

        public UInt32 RecordNo
        {
            get { return mHolder.RecordNo; }
        }

        public void SaveChanges()
        {
            mHolder.SaveChanges(this);
        }

        #region IDisposable Members

        void IDisposable.Dispose()
        {
            mHolder.OnRecordDisposed(this);
            GC.SuppressFinalize(this);
        }

        ~Record()
        {
#if DUMP_FINALIZE
            System.Diagnostics.Trace.WriteLine("Entering Destructor " + this.GetType().Name + " #" + mHolder.mRecordNo);
#endif
            mHolder.OnRecordDisposed(this);
        }

        protected void SetColumnValue(DbfColumn column, object value)
        {
            throw new NotImplementedException();
        }

        protected object GetColumnValue(DbfColumn column)
        {
            throw new NotImplementedException();
        }


        protected DbfDotNet.DbfColumn GetColumn(string name)
        {
            throw new NotImplementedException();
        }

        protected DbfDotNet.DbfColumn GetColumn(int index)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
